package com.example.lcode.test;


import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.chrono.MinguoChronology;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

/**
 * @version 1.0
 * @author: ChuJie_Lin
 * @since: 2021-12-13 10:08
 **/
public class test1 {



    // 3

    // 4

    // 5


    /**
     *
     * @param list1 list1产品基础数据
     * @param list2 产品详细数据
     * @param entryKey 关联entryKey名称
     * @return 返回的合并数据
     */
    public List<Map<String,Object>> unionArraySameEntryKey(List<Map<String,Object>> list1,
                                                           List<Map<String,Object>> list2,String entryKey) {
        if (CollectionUtils.isEmpty(list1)
                || CollectionUtils.isEmpty(list2)
                || entryKey == null) {
            return new ArrayList<>();
        }
        List<Map<String, Object>> res = new ArrayList<>();
        list1.stream().filter(item -> item.get(entryKey) != null).forEach(productBase -> {
            res.add(relateProductDetail(productBase, entryKey, list2));
        });
        return res;
    }

    private Map<String, Object> relateProductDetail(Map<String, Object> productBase,
                                     String entryKey,
                                     List<Map<String, Object>> list2) {
        Map<String,Object> prodcutInfo = new HashMap<>();
        prodcutInfo.putAll(productBase);
        String productBaseStr = productBase.get(entryKey).toString();
        list2.stream().forEach(procuctDetail -> {
            Object procuctDetailObject = procuctDetail.get(entryKey);
            if (procuctDetailObject != null && productBaseStr.equalsIgnoreCase(procuctDetailObject.toString())) {
                prodcutInfo.putAll(procuctDetail);
                return;
            }
        });
        return prodcutInfo;
    }


    public static void main(String[] args) {
        String.valueOf(null);
    }




}
